package com.jlastu.dlxy_androidapp.view.headers;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.jlastu.dlxy_androidapp.R;

public class SchoolHeader extends LinearLayout {

    private TextView mTitleView;
    private TextView mButtonLeft;
    private TextView  mButtonCenter;
    private TextView  mButtonRight;

    public SchoolHeader(Context context) {
        super(context);
        initView();
    }

    public SchoolHeader(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView();

    }

    private void initAttrs(Context context, AttributeSet attrs){
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ClassHeader);
        String titleText = typedArray.getString(R.styleable.ClassHeader_titleText);
        String leftText = typedArray.getString(R.styleable.ClassHeader_leftText);
        String centerText = typedArray.getString(R.styleable.ClassHeader_centerText);
        String rightText = typedArray.getString(R.styleable.ClassHeader_rightText);
        typedArray.recycle();
        setTitle(titleText);
        setButtonLeft(leftText);
        setButtonCenter(centerText);
        setButtonRight(rightText);

    }

    private void initView() {
        LayoutInflater.from(getContext()).inflate(R.layout.school_head, this, true);
        mTitleView = findViewById(R.id.text_title);
        mButtonLeft = findViewById(R.id.button_left);
        mButtonCenter = findViewById(R.id.button_center);
        mButtonRight = findViewById(R.id.button_right);
        mButtonLeft.setSelected(true);
    }

    public void setTitle(String title){
        if (mTitleView != null && !TextUtils.isEmpty(title)){
            mTitleView.setText(title);

        }

    }

    public void setButtonLeft(String title){
        if (mTitleView != null && !TextUtils.isEmpty(title)){
            mTitleView.setText(title);

        }

    }
    public void setButtonCenter(String title){
        if (mTitleView != null && !TextUtils.isEmpty(title)){
            mTitleView.setText(title);

        }

    }
    public void setButtonRight(String title){
        if (mTitleView != null && !TextUtils.isEmpty(title)){
            mTitleView.setText(title);

        }

    }


    public void setLeftClickListener(OnClickListener listener) {
        mButtonLeft.setOnClickListener(listener);


    }

    public void setCenterClickListener(OnClickListener listener) {
        mButtonCenter.setOnClickListener(listener);


    }

    public void setRightClickListener(OnClickListener listener) {
        mButtonRight.setOnClickListener(listener);


    }
    public String getCenterText(){
        return mButtonCenter.getText().toString().trim();
    }
    public String getRightText(){
        return mButtonRight.getText().toString().trim();
    }

    public void setLeftSelector(){
        mButtonLeft.setSelected(true);
        mButtonCenter.setSelected(false);
        mButtonRight.setSelected(false);
    }
    public void setCenterSelector(){
        mButtonLeft.setSelected(false);
        mButtonCenter.setSelected(true);
        mButtonRight.setSelected(false);
    }
    public void setRightSelector(){
        mButtonLeft.setSelected(false);
        mButtonCenter.setSelected(false);
        mButtonRight.setSelected(true);
    }


}
